#include "LED_Handler.h"


extern stateMachine sChargerState;
uint8 u8LED_BlinkCounter;

void vfnLED_Management (void)
{
    if (sChargerState.u8currentState & WAIT_FOR_SUN2)
    {
        POWER_LED = 0;
        CHARGING_LED = 0;
    }
    else
    {
        POWER_LED = 1;
    }

    if((sChargerState.u8currentState & TRICKLE_CHARGE) || 
       (sChargerState.u8currentState & CONSTANT_CURRENT))
    {
        // Charging LED blinks
        if(u8LED_BlinkCounter)
        {
            u8LED_BlinkCounter--;    
        }
        else
        {
            CHARGING_LED ^= 1;
            u8LED_BlinkCounter = 63;
        }
    }
    if (sChargerState.u8currentState & CONSTANT_VOLTAGE)
    {
    	CHARGING_LED = 1;
    }
    else
    {
        if((sChargerState.u8currentState & WAIT_FOR_BATTERY) && 
        (sChargerState.u8prevState & CONSTANT_VOLTAGE))
        {
        	POWER_LED = 0;
            CHARGING_LED = 1;   
        }
    }
}


void vfnLED_Init (void)
{
    // Configure the pin driving the green LED as an output
    CHARGING_LED = 0;
    CHARGING_LED_DD =  GPIO_OUTPUT;
    
    // Configure the pin driving the red LED as an output
    POWER_LED = 0;
    POWER_LED_DD =    GPIO_OUTPUT;    
}